package com.park.web.config;

import com.park.web.Interceptor.apiInterceptor;
import com.park.web.Interceptor.loginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: admin
 * @description:
 * @author: Mr.Chen
 * @create: 2018-07-20 11:18
 **/
@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/staticResource/**").addResourceLocations("file:./staticResource/");
        registry.addResourceHandler("/PLWC-Web/**").addResourceLocations("file:./staticResource/");
    }

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new apiInterceptor())
                .addPathPatterns("/api/**");
        registry.addInterceptor(new loginInterceptor())
                .addPathPatterns("/**").excludePathPatterns("/hi", "login", "/error", "/Attach/**", "/api/**", "/login/**", "/loginAction", "/staticResource/**");
    }
    //允许跨域访问
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                .maxAge(3600);
    }
}